const visitModel = require('@/models/visit.model')
const Service = require('./index')

class VisitService extends Service {
  async findPageList (pageNo = 1, pageSize = 20, { searchKeywords, path, startTime, endTime }) {
    try {
      const { list, total } = await visitModel.findList(pageNo, pageSize, {
        andConditions: {
          equal: {
            'visit.path': path
          },
          like: {
            'visit.ip': searchKeywords
          }
        },
        betweenConditions: {
          'visit.date': [startTime, endTime]
        }
      })
      return this.skipPage(list, total, pageNo, pageSize)
    } catch (error) {
      throw new Error(error)
    }
  }
}

module.exports = new VisitService()
